<script setup>

import {qrCodeScan, moniLogin, qrcodeStatus} from "@/api/qrcode/moni.js";
import {onMounted, onUnmounted} from "vue";

function moniScan() {


  const data = {
    "qrCode": "dd594dda.jpg",
    "scanUser": "1"
  };

  qrCodeScan(data).then(res => {
    console.log("用户扫码成功");
  })

}

function domoniLogin() {
  const data = {
    "qrCode": "dd594dda.jpg",
    "scanUser": "1"
  };
  moniLogin(data).then(res => {
    console.log("用户登录成功");
  })
}


let intervalFlush //定时器
// 定时器 每5秒调用一次接口
const interval = () => {
  clearInterval(intervalFlush)
  intervalFlush = setInterval(() => {
    // 此处你要轮巡的接口
    qrcodeStatus(null).then(res => {
      console.log(res);
      if (res.code === 200) {
        clearInterval(intervalFlush)
        console.log("扫码成功");

      }

    });

  }, 1000)
};
onMounted(() => {
  // 设置定时器
  interval()
});
onUnmounted(() => {
  // 离开页面销毁定时器

  clearInterval(intervalFlush)
});


</script>

<template>
  <a-button @click="moniScan">用于模拟移动端 扫码操作</a-button>
  <a-button @click="domoniLogin">用于模拟移动端 确定登录</a-button>

  <br>

</template>

<style scoped>

</style>
